package cn.sunline.test.api.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.sunline.test.api.model.Account;
import cn.sunline.test.api.model.User;
import cn.sunline.test.api.service.remote.AccountService;
import cn.sunline.test.api.service.remote.UserService;

@Service
public class RegisterService {
	private static final Logger log = LoggerFactory.getLogger(RegisterService.class);
	
	@Autowired
	UserService userService;
	@Autowired
	AccountService accountService;
	
	public String register(String userName, String email){
		User user = new User();
		user.setUser_name(userName);
		user.setEmail(email);
        user = userService.add(user);
        log.info("add user return info :" + user.toString());
        Account account = new Account();
        account.setUser_id(user.getId());
        account.setUser_name(user.getUser_name());
        account = accountService.add(account);
        log.info("add account return info :" + account.toString());
        return user.toString() + " | " + account.toString();
	}
}
